package com.platform.modules.mall.activityV2.restrict;


import com.platform.common.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class RestrictFactoryV2 {

    @Resource(name = "whitelistLevelRestrict")
    private WhitelistLevelRestrict whitelistLevelRestrict;
    @Resource(name = "whitelistNumberRestrict")
    private WhitelistNumberRestrict whitelistNumberRestrict;
    @Resource(name = "noRestrict")
    private NoRestrict noRestrict;

    public RestrictInterfaceV2 restrictInterface(int whitelistConfine){

        if (ConfineType.LEVEL_CONFINE.getType().equals(whitelistConfine)){
            /*手机白名单等级限制*/
            return whitelistLevelRestrict;
        }else if (ConfineType.NUMBER_CONFINE.getType().equals(whitelistConfine)){
            /*手机白名单数量限制*/
            return whitelistNumberRestrict;
        }else if (ConfineType.NO_CONFINE.getType().equals(whitelistConfine)){
            /*无限制*/
            return noRestrict;
        }
        throw new BusinessException("没有指定的活动参与规则");
    }

    private enum ConfineType{
        /**
         * 无限制
         */
        NO_CONFINE(0),
        /**
         * 白名单等级规则
         */
        LEVEL_CONFINE(1),
        /**
         * 白名单数量规则
         */
        NUMBER_CONFINE(2);

        private Integer type;
        ConfineType(Integer type){
            this.type=type;
        }
        public Integer getType(){
            return this.type;
        }
    }
}
